package com.ymttest.database.mongo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.core.tool.Logger;
import com.ymt.database.MongoDBDriver;

public class ProductCatalogInfoWapper {
	MongoDBDriver mdd =  YmtMongoDriverFactroy.getInstance_YmtProductDBdriver("ProductCatalogInfo");
	
	 public ProductCatalogInfoWapper() {
	    }
	 
	  
	    public Map<String, Object> getByCatalogId(String catalogId) throws Exception {
	        Map<String, Object> scmb = new HashMap<String, Object>();
	        ArrayList<Map> list = mdd.selectPartLimitToMap("{\"CatalogId\":\"" + catalogId + "\"}",1);
	             try {
	            if (list.size() > 0) {
	                scmb = list.get(0);
	                return scmb;
	            }
	        } catch (Exception e) {
	            Logger.debug("err data catalogId:" + catalogId);
	            e.printStackTrace();
	        }
	        return null;
	    }
	    /**
	     * New
	     * @param catalogId
	     * @return
	     * @throws Exception
	     */
	    public Map<String, Object> getProductCategoryInfoById(String catalogId) throws Exception {
	    	mdd =  YmtMongoDriverFactroy.getInstance_YmtProductDBdriverNew("ProductCategoryInfo");
	        Map<String, Object> scmb = new HashMap<String, Object>();
	        ArrayList<Map> list = mdd.selectPartLimitToMap("{\"CategoryId\":" + catalogId + "}",1);
	             try {
	            if (list.size() > 0) {
	                scmb = list.get(0);
	                return scmb;
	            }
	        } catch (Exception e) {
	            Logger.debug("err data catalogId:" + catalogId);
	            e.printStackTrace();
	        }
	        return null;
	    }
	    /**
	     * New
	     * @param limit
	     * @return
	     * @throws Exception
	     */
	    public ArrayList<Map> getProductCategoryInfoLimit(int limit) throws Exception {
	    	if(limit<1){
	    		limit=1;
	    	}
	    	mdd =  YmtMongoDriverFactroy.getInstance_YmtProductDBdriverNew("ProductCategoryInfo");
	        Map<String, Object> scmb = new HashMap<String, Object>();
	        ArrayList<Map> list = mdd.selectPartLimitToMap("{}",limit);
	             try {
	            if (list.size() > 0) {
	                return list;
	            }
	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return null;
	    }
	    public static void main(String[] args) throws Exception {
	    	new ProductStockInfoWapper().getByCatalogId("8adfc4c1-2e3c-46f3-91d3-3c4bed3378f9");
		}
	 
}
